#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 410;
const int H[] = { 0, -1, 0, 1 };
const int L[] = { -1, 0, 1, 0 };

int vis[N][N], ans[N][N];
char s[N][N];
int R, C, cnt;

void dfs(int x, int y, int dir) {
	if(x <= 0 || x > R || y <= 0 || y > C) return;
	if(vis[x][y] != 0) return (vis[x][y] == -1) && (cnt = R * C * 2 + 100), void();
	cnt+=2; vis[x][y] = -1; dfs(x + H[dir], y + L[dir], dir);
	if(s[x][y] == 'N') dir ^= 3; else dir ^= 1; dfs(x + H[dir], y + L[dir], dir);
	vis[x][y] = 1;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    R = in, C = in;
	rep(i, 1, R) scanf("%s", s[i] + 1);
	memset(ans, 0x3f, sizeof ans);
	rep(i, 1, R) {
		memset(vis, 0, sizeof vis); cnt = 0;
		rep(j, 1, C) dfs(i, j, 0), ans[i][j] = min(ans[i][j], cnt);
		memset(vis, 0, sizeof vis); cnt = 0;
		per(j, C, 1) dfs(i, j, 2), ans[i][j] = min(ans[i][j], cnt);
		rep(j, 1, C) printf("%d%c", ans[i][j] > R * C * 2 ? -1 : ans[i][j], " \n"[j == C]);
	}
}
